package com.changgou.gateway.web.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.HttpCookie;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;

@Component
public class AuthService {

    @Autowired
    private RedisTemplate redisTemplate;

    public String getJtiFromCookie(ServerHttpRequest request){
//        String jti = null;
//        HttpCookie uid = request.getCookies().getFirst("uid");
//        if(uid == null){
//            redisTemplate.boundHashOps()
//            jti = "057ff010-92a1-4225-8b3e-8e97b8f3f79b";
//        }else{
//            jti = uid.getValue();
//        }
//        return jti;
        HttpCookie httpCookie = request.getCookies().getFirst("uid");
        if (httpCookie != null){
            String jti = httpCookie.getValue();
            return jti;
        }
        return null;
    }


    public String getTockenFromRedis(String jti){
        String token = (String) redisTemplate.boundValueOps(jti).get();
        return token;
    }

}
